//
//  MessageDetailViewController.m
//  SP2P
//
//  Created by 吴建东 on 16/2/29.
//  Copyright © 2016年 EIMS. All rights reserved.
//

#import "MessageDetailViewController.h"

@interface MessageDetailViewController ()<HTTPClientDelegate,UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIImageView *logoImageView;

@property(nonatomic ,strong) NetWorkClient *requestClient;

@end

@implementation MessageDetailViewController
#pragma mark - Life Cycle
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if (_requestClient != nil) {
        [_requestClient cancel];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self initNavBarTitle:@"公告详情" andLeftItemName:@"返回" andRightItemName:@""];
    self.view.backgroundColor = [UIColor whiteColor];
    
    _titleLabel.text = _messageModel.title;
    _timeLabel.text  = _messageModel.detailTimes;
    
    _webView.backgroundColor = KbackgroundColor;
    _webView.delegate = self;
    _webView.scrollView.scrollEnabled = NO;
    _webView.frame = RECTMAKE(0, GetMinY(_webView), MSWIDTH, MSHIGHT - 64 - 65);
    _webView.scrollView.backgroundColor = KbackgroundColor;
    _webView.scrollView.showsHorizontalScrollIndicator = NO;
    _webView.scrollView.showsVerticalScrollIndicator = NO;
    [_webView loadHTMLString:_messageModel.originContent baseURL:[NSURL URLWithString:Baseurl]];
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    CGRect frame = webView.frame;
    frame.size.width = MSWIDTH;
    frame.size.height = 1;
    //    wb.scrollView.scrollEnabled = NO;
    webView.frame = frame;
    frame.size.height = webView.scrollView.contentSize.height;
    
    webView.frame = frame;
    
    frame = _logoImageView.frame;
    frame.origin.y = GetMaxY(webView);
    _logoImageView.frame = frame;
    _logoImageView.image = [UIImage imageNamed:@"public_logo"];
    
    _scrollView.contentSize = CGSizeMake(0, GetMaxY(_logoImageView) + 10);
}

#pragma mark - Data
- (void)requestData {
    // 标记为已读，发送请求给服务器
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:@"85" forKey:@"OPT"];
    [parameters setObject:@"" forKey:@"body"];
    [parameters setObject:AppDelegateInstance.userInfo.userId forKey:@"id"];
    [parameters setObject:_messageModel.messageId forKey:@"ids"];
    
    if (_requestClient == nil) {
        _requestClient = [[NetWorkClient alloc] init];
        _requestClient.delegate = self;
    }
    [_requestClient requestGet:@"app/services" withParameters:parameters];
}

#pragma - HTTPClientDelegate 网络数据回调代理
-(void) startRequest {
    
}

// 返回成功
-(void) httpResponseSuccess:(NetWorkClient *)client dataTask:(NSURLSessionDataTask *)task didSuccessWithObject:(id)obj {
    NSDictionary *dics = obj;
    DLOG(@"=标为已读返回成功=======%@",dics);
    if ([[NSString stringWithFormat:@"%@",[dics objectForKey:@"error"]] isEqualToString:@"-1"]) {
        
        
    }else if ([[NSString stringWithFormat:@"%@",[dics objectForKey:@"error"]] isEqualToString:@"-2"]) {
        //[ReLogin outTheTimeRelogin:self];
    }else {
        //[SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@", [obj objectForKey:@"msg"]]];
    }
}

// 返回失败
-(void) httpResponseFailure:(NetWorkClient *)client dataTask:(NSURLSessionDataTask *)task didFailWithError:(NSError *)error {
    // 服务器返回数据异常
    //    [SVProgressHUD showErrorWithStatus:@"网络异常"];
}

// 无可用的网络
-(void) networkError {
    //[SVProgressHUD showErrorWithStatus:@"无可用网络"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
